; *******************************************************************
;   gobj_application.ahk
; *******************************************************************

; -------------------------------------------------------------------
;   includes
; -------------------------------------------------------------------

; #include filex.ahk                            

; -------------------------------------------------------------------
;   gobj_application
; -------------------------------------------------------------------

class gobj_application
{
  _priv_  := { forms: {} }
	
  ; -----------------------------------------------------------------
  ;   __Set
  ; -----------------------------------------------------------------

  __Set(aName, aValue)
  {
    global gobj_application_instance
    gobj_application_instance := this
    if (aValue.HasKey("_priv_"))
    {
      if (aValue._priv_.HasKey("controls"))
      {
        this._priv_.forms.Insert(aName, aValue)
        aValue._priv_.GuiName := aName
        aValue._priv_.GuiNameAssigned := true
        Gui %aName%:New
        Gui %aName%:+Labelgobj_on
        Gui %aName%:Show, Hide 
        aValue._init_post()
        return aValue
      }
    }
  }

  ; -----------------------------------------------------------------
  ;   __Get
  ; -----------------------------------------------------------------

  __Get(aName)
  {
    if (this._priv_.forms.HasKey(aName))
    {
      return this._priv_.forms[aName]
    }
  }

  ; -----------------------------------------------------------------
  ;   OnCommand
  ; -----------------------------------------------------------------

  OnCommand(form, cntl)
  {
    for k, v in this._priv_.forms
    {
      if (form == k)
    	v.OnCommand(form, cntl)
    }
  }

  ; -----------------------------------------------------------------
  ;   OnSize
  ; -----------------------------------------------------------------

  OnSize(form, w, h)
  {
    for k, v in this._priv_.forms
    {
      if (form == k)
    	v.OnSize(w, h)
    }
  }

  ; -----------------------------------------------------------------
  ;   OnClose
  ; -----------------------------------------------------------------

  OnClose(form)
  {
    for k, v in this._priv_.forms
    {
      if (form == k)
    	v.OnClose()
    }
  }

  ; -----------------------------------------------------------------
  ;   OnEscape
  ; -----------------------------------------------------------------

  OnEscape(form)
  {
    for k, v in this._priv_.forms
    {
      if (form == k)
    	v.OnEscape()
    }
  }
}

; -------------------------------------------------------------------
;   event handling
; -------------------------------------------------------------------

gobj_onSize:
  gobj_application_instance.OnSize(A_Gui, A_GuiWidth, A_GuiHeight)
return

gobj_onClose:
  gobj_application_instance.OnClose(A_Gui)
return

gobj_onEscape:
  gobj_application_instance.OnEscape(A_Gui)
return

gobj_command:
  gobj_application_instance.OnCommand(A_Gui, A_GuiControl)
return

